package com.augurit.gzcgwsp.qyzz.convert;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.gzcgwsp.qyzz.entity.YwRqQyzzInfo;
import com.augurit.gzcgwsp.qyzz.web.form.YwRqQyzzInfoForm;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.YwRqQyzzInfoForFx;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;

public class YwRqQyzzInfoConvertor {
    public static YwRqQyzzInfoForm convertVoToForm(YwRqQyzzInfo entity) {
        if (entity == null) return null;
        YwRqQyzzInfoForm form = new DozerBeanMapper().map(entity, YwRqQyzzInfoForm.class);
        
		form.setAcceptNo2(entity.getAcceptNo());
		form.setCbyw2(entity.getCbyw());
		form.setCbyw3(entity.getCbyw());
		form.setCbyw4(entity.getCbyw());
		form.setSjr2(entity.getSjr());
		form.setSqdw2(entity.getSqdw());
		form.setSqrq2(entity.getIeiDate());
		if(entity.getIeiDate() != null){
			form.setSqrq3(entity.getIeiDate());
			form.setSqrq4(entity.getIeiDate());
		}else{
			form.setSqrq3(new Date());
			form.setSqrq4(new Date());
		}
		
		form.setCurDate(DateUtils.dateTimeToString(new Date(), DateUtils.YEAR_MOUTH_DAY_));
		form.setCurDate2(form.getCurDate());
		form.setCurDate3(form.getCurDate());
        
        return form;
    }
    
    public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, YwRqQyzzInfoForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new YwRqQyzzInfoForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
    }
    
    public static void convertFormToQyxxForm(YwRqQyzzInfoForm form, YwComQyxxForm qyxxForm) {
        if (form == null) return;
        if (qyxxForm == null) qyxxForm = new YwComQyxxForm();
        
        new DozerBeanMapper().map(form, qyxxForm);
        qyxxForm.setId(form.getQyid());
    }
    
    public static void convertFormToVo(YwRqQyzzInfoForm form, YwRqQyzzInfo entity) {
        if (form == null) return;
        if (entity == null) entity = new YwRqQyzzInfo();
        
        new DozerBeanMapper().map(form, entity);
    }
    
    public static List<YwRqQyzzInfoForm> convertVoListToFormList(List<YwRqQyzzInfo> ywRqInstallentinfoList) {
        if(ywRqInstallentinfoList != null && ywRqInstallentinfoList.size() > 0) {
            List<YwRqQyzzInfoForm> ywRqInstallentinfoFormList = new ArrayList();
            for(int i=0; i<ywRqInstallentinfoList.size(); i++) {
                ywRqInstallentinfoFormList.add(convertVoToForm(ywRqInstallentinfoList.get(i)));
            }
            return ywRqInstallentinfoFormList;
        }
        return null;
    }
    
    public static List<YwRqQyzzInfo> convertFormListToVoList(List<YwRqQyzzInfoForm> ywRqInstallentinfoFormList) {
        if(ywRqInstallentinfoFormList != null && ywRqInstallentinfoFormList.size() > 0) {
            List<YwRqQyzzInfo> ywRqInstallentinfoList = new ArrayList();
            for(int i=0; i<ywRqInstallentinfoFormList.size(); i++) {
                YwRqQyzzInfo ywRqQyzzInfo = new YwRqQyzzInfo();
                convertFormToVo(ywRqInstallentinfoFormList.get(i), ywRqQyzzInfo);
                ywRqInstallentinfoList.add(ywRqQyzzInfo);
            }
            return ywRqInstallentinfoList;
        }
        return null;
    }
    
    public static void convertFormToYwRqQyzzInfoForFx(YwRqQyzzInfoForm form, YwRqQyzzInfoForFx entity) {
        if (form == null) return;
        if (entity == null) entity = new YwRqQyzzInfoForFx();   
        if(StringUtils.isNotEmpty(form.getAddress())){
        	entity.setIeiAddress(form.getAddress());
        }
        if(StringUtils.isNotEmpty(form.getEmail())){
        	entity.setIeiEmail(form.getEmail());
        }
        if(StringUtils.isNotEmpty(form.getPost())){
        	entity.setIeiPost(form.getPost());
        }
        if(StringUtils.isNotEmpty(form.getYwlxr())){
        	entity.setIeiLinkman(form.getYwlxr());
        }
        if(StringUtils.isNotEmpty(form.getYwlxrtel())){
        	entity.setIeiTel(form.getYwlxrtel());
        }
        if(StringUtils.isNotEmpty(form.getZczj())){
        	entity.setIeiRegmoney(form.getZczj());
        }
        if(StringUtils.isNotEmpty(form.getCsmj())){
        	entity.setIeiArea(form.getCsmj());
        }
        if(StringUtils.isNotEmpty(form.getFddbr())){
        	entity.setIeiHost(form.getFddbr());
        }
        if(StringUtils.isNotEmpty(form.getZsbh())){
        	entity.setIeiLicensenum(form.getZsbh());
        }
        if(StringUtils.isNotEmpty(form.getZzdj())){
        	entity.setIeiIntegernum(form.getZzdj());
        }
        if(StringUtils.isNotEmpty(form.getGszcdjh())){
        	entity.setIeiLicence(form.getGszcdjh());
        }
        if(StringUtils.isNotEmpty(form.getJjlx())){
        	entity.setIeiKind(form.getJjlx());
        }
        if(StringUtils.isNotEmpty(form.getRsJsry())){
        	entity.setIeiTechpeop(form.getRsJsry());
        }
        if(StringUtils.isNotEmpty(form.getRsWxg())){
        	entity.setIeiInstallpeop(form.getRsWxg());
        }
        if(StringUtils.isNotEmpty(form.getRsTotal())){
        	entity.setIeiTotalpeop(form.getRsTotal());
        }
        if(StringUtils.isNotEmpty(form.getDwslJyrq())){
        	entity.setIeiJynum(form.getDwslJyrq());
        }
        if(StringUtils.isNotEmpty(form.getDwslGyrq())){
        	entity.setIeiGfnum(form.getDwslGyrq());
        }
        if(StringUtils.isNotEmpty(form.getQyRemarks())){
        	entity.setIeiEntinst(form.getQyRemarks());
        }
        new DozerBeanMapper().map(form, entity);
    }
}